package com.lm.controller;

import com.lm.pojo.*;
import com.lm.service.SignService;
import com.lm.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.transform.Result;
import java.util.List;

/**
 * @author 苟
 * @version 1.0
 * @description: TODO 签约管理控制层
 * @date 2025/9/22 10:26
 */
@CrossOrigin
@Api(tags = "签约管理")
@RestController
@RequestMapping("/sign")
public class SignController {
    @Autowired
    private SignService signService;

    @ApiOperation(value = "查询签约列表", httpMethod = "GET" ,notes = "查询所有签约信息")
    @GetMapping("/findSignList")
    public ResultUtil<List<Sign>>findSignList(){
        try {

            return new ResultUtil<>(200, "查询成功", signService.findSignList());
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "查询失败");
        }
    }
    @ApiOperation(value = "查询签约列表", httpMethod = "GET" ,notes = "查询所有签约信息")
    @GetMapping("/findSignRecord")
    public ResultUtil<List<Sign>>findSignRecord(){
        try {
            return new ResultUtil<>(200, "查询成功", signService.findSignRecord());
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "查询失败");
        }
    }

    @ApiOperation(value = "查询签约列表", httpMethod = "GET" ,notes = "查询所有签约信息")
    @GetMapping("/handleQuery")
    public ResultUtil<List<Sign>>handleQuery(Sign sign){
        try {
            return new ResultUtil<>(200, "查询成功", signService.handleQuery(sign));
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "查询失败");
        }
    }



    @ApiOperation(value = "查询居民列表", httpMethod = "GET" ,notes = "查询所有居民信息")
    @GetMapping("/findResident")
    public ResultUtil<List<Resident>>findResident(){
        try {
            List<Resident> list = signService.findResident();
            return new ResultUtil<>(200, "查询成功", list);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "查询失败");
        }
    }

    @ApiOperation(value = "审核通过",httpMethod = "GET",notes = "通过审核")
    @GetMapping("/passReview")
    public ResultUtil passReview(Integer signId,Integer signStatus){
        try {
            signService.passReview(signId,signStatus);
            return new ResultUtil(200,"通过成功");
        }catch (Exception e){
            e.printStackTrace();
            return new ResultUtil(500,"通过失败");
        }
    }

    @ApiOperation(value = "驳回通过",httpMethod = "GET",notes = "驳回通过")
    @GetMapping("/rejectReview")
    public ResultUtil rejectReview(Integer signId,Integer signStatus,String signRejectDesc){
        try {
            signService.rejectReview(signId,signStatus,signRejectDesc);
            return new ResultUtil(200,"通过成功");
        }catch (Exception e){
            e.printStackTrace();
            return new ResultUtil(500,"通过失败");
        }
    }

    @ApiOperation(value = "保存修改",httpMethod = "POST",notes = "保存修改")
    @PostMapping("/passUpdateSign")
    public ResultUtil passUpdateSign(@RequestBody Sign sign){
        try {
            signService.passUpdateSign(sign);
            return new ResultUtil(200,"通过成功");
        }catch (Exception e){
            e.printStackTrace();
            return new ResultUtil(500,"通过失败");
        }
    }


    @ApiOperation(value = "保存修改",httpMethod = "POST",notes = "保存修改")
    @PostMapping("/passUpdateRecord")
    public ResultUtil passUpdateRecord(@RequestBody Sign sign){
        try {
            signService.passUpdateRecord(sign);
            return new ResultUtil(200,"通过成功");
        }catch (Exception e){
            e.printStackTrace();
            return new ResultUtil(500,"通过失败");
        }
    }

    @ApiOperation(value = "保存新增",httpMethod = "POST",notes = "保存新增")
    @PostMapping("/passAddSign")
    public ResultUtil passAddSign(@RequestBody Sign sign){
        try {
            signService.passAddSign(sign);
            return new ResultUtil(200,"通过成功");
        }catch (Exception e){
            e.printStackTrace();
            return new ResultUtil(500,"通过失败");
        }
    }

}
